package com.zhixing.common.utils;

import com.zhixing.common.domain.enums.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Res<T> {
    /**
     * 状态码
     * @example 200
     */
    int code;

    /**
     * 消息
     * @example OK
     */
    String msg;

    /**
     * 数据
     */
    T data;

    public static <T> Res<T> ok(T data) {
        return new Res<>(HttpStatus.OK.getCode(), HttpStatus.OK.getMsg(), data);
    }

    public static <T> Res<T> ok() {
        return Res.ok(null);
    }

    public static <T> Res<T> error(int code, String msg) {
        return new Res<>(code, msg, null);
    }

    public static <T> Res<T> error(HttpStatus httpStatus) {
        return Res.error(httpStatus.getCode(), httpStatus.getMsg());
    }
}
